package com.cskaoyan.wxcontroller;

import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.collect.CollectBO;
import com.cskaoyan.bean.domain.User;
import com.cskaoyan.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("wx/collect")
public class WxCollectController {

    @Autowired
    CollectService service;

    @ResponseBody
    @PostMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody CollectBO collectBO) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId = user.getId();

        service.addordelete(collectBO, userId);
        return BaseRespVo.ok(null);
    }

    @ResponseBody
    @GetMapping("list")
    public BaseRespVo getList(Integer page, Byte type, Integer limit) {

        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId = user.getId();

        BaseData baseData = service.getList(page, limit, type, userId);
        return BaseRespVo.ok(baseData);
    }


}
